package khleuven.mondzorg.domain;

import khleuven.mondzorg.Logger;

import org.json.JSONObject;

public class Definition extends Entry {

	private String definition;
	private String explanation;

	@Deprecated
	public Definition(Language taal, DestinationGroup doelpubliek, String definition, String explanation) throws DomainException {
		super(EntryType.DEFINITION, taal, doelpubliek);
		setDefinition(definition);
		setExplanation(explanation);
	}
	
	public Definition(JSONObject object) throws DomainException{
		super(EntryType.DEFINITION, object);		
		setDefinition(JsonKeysDictionary.getStringItem(object, JsonKeysDictionary.JSON_KEY_DEF_NAME));
		setExplanation(JsonKeysDictionary.getStringItem(object, JsonKeysDictionary.JSON_KEY_DEF_EXPLANATION));
		Logger.logDomain(toString());
	}
	
	public String getDefinition() {
		return definition;
	}

	public void setDefinition(String definition) {
		this.definition = definition;
	}

	public String getExplanation() {
		return explanation;
	}

	public void setExplanation(String explanation) {
		this.explanation = explanation;
	}
	
	@Override
	public boolean equals(Object o){
		boolean gelijk = false;
		if(o instanceof Definition){
			Definition d = (Definition)(o);
			if(super.equals(d) && d.getDefinition().equals(getDefinition())
					&& d.getExplanation().equals(getExplanation())){
				gelijk = true;
			}
		}
		return gelijk;
	}
	
	@Override
	public String toString(){
		return super.toString()+getDefinition()+" - "+getExplanation();				
	}
	
	@Override
	public JSONObject toJSon() throws DomainException {
		JSONObject output = super.toJSon();
		JsonKeysDictionary.toStringItem(output, JsonKeysDictionary.JSON_KEY_DEF_NAME, getDefinition());
		JsonKeysDictionary.toStringItem(output, JsonKeysDictionary.JSON_KEY_DEF_EXPLANATION, getExplanation());
		return output;		
	}

	@Override
	public String makeStringForList() {
		return getDefinition();
	}
	
	@Override
	public int compareTo(Entry t) {
		int r = super.compareTo(t);
		if(r == 0) {
			Definition o = (Definition)t; 
			// CCE not possible because of super.compareTo(t)
			return this.getDefinition().compareTo(o.getDefinition());
		} else {
			return r;
		}
	}

}
